//
//  ChildHoodMemory.m
//  ChildHoodStemp
//
//  Created by xuzuotao on 13-9-8.
//
//

#import "ChildHoodMemory.h"
//#import "CHMemoryManager.h"

@interface ChildHoodMemory()
-(NSString*)getGroupName;
-(NSString*)fileName;
-(BOOL)getIsFollowed;
@end


@implementation ChildHoodMemory
@synthesize snspMemory = _snspMemory;
@synthesize profilePictureUri;
@synthesize profilePictureNextUri;
@synthesize groupName;
@synthesize hasChild;
@synthesize name;
@synthesize nickName;
@synthesize organizationName;
@synthesize sex;
@synthesize profileTitle;
@synthesize classId;
@synthesize signature;
@synthesize memoryId;
@synthesize isChild;
@synthesize policy;
@synthesize isFollowed;
@synthesize checkCode;
@synthesize pairsList;
@synthesize postsList;
@synthesize photosList;

@synthesize nonFirstMessagePull;
@synthesize nonFirstNoticePull;
@synthesize permission;

@synthesize contactGroup = _contactGroup;
@synthesize myClassID = _myClassID;

#define Unknown @""


static NSMutableDictionary* profilePictures = nil;;

-(id)initWithMemory:(SNSPMemory*)snspMemory
{
    if( self = [super init])
    {
        if(profilePictures == nil)
        {
            profilePictures = [[NSMutableDictionary alloc]initWithCapacity:4];
        }
        self.nonFirstMessagePull = NO;
        self.nonFirstMessagePull = NO;
        _contactGroup = 0;
        _snspMemory = snspMemory;
    }
    return self;
    
}

-(id)initWithMemory:(SNSPMemory*)snspMemory andGroup:(ContactsGroupType)group
{
    if(self = [self initWithMemory:snspMemory])
    {
        self.nonFirstMessagePull = NO;
        self.nonFirstMessagePull = NO;
        _contactGroup = group;
    }
    return self;
    
}

-(void)dealloc
{
//    NSLog(@"ChildHoodMemory dealloc");
}

-(NSString*)getProfilePictureUri
{
    NSString *uri = nil;
    
   if(_snspMemory.hasAvatarFileKey)
   {
       return nil;
   }
    
    /*if(_snspMemory.hasMiniAvatarUrl)
        return _snspMemory.miniAvatarUrl;*/
    
    
    /*if(_snspMemory.hasProfilePicture)
    {
        if(_snspMemory.profilePicture.materialType ==SNSPMaterialTypeKImage)
        {
            NSString* imageUri = nil;
            if(_snspMemory.profilePicture.hasFileUri)
            {
                imageUri  = _snspMemory.profilePicture.fileUri;
            }
            return imageUri;
        }
        
    }*/
    
    switch ([self getSex]) {
        case SNSPSexKMale:
            uri = @"headImage_boy.png";
            break;
        case SNSPSexKFemale:
            uri = @"headImage_girl.png";
            break;
        default:
            break;
    }
    return uri;
}

-(NSString*)getProfilePictureNextUri
{
    /*if(_snspMemory.hasProfilePicture)
    {
        if(_snspMemory.profilePicture.materialType ==SNSPMaterialTypeKImage)
        {
            if(_snspMemory.profilePicture.hasNextFileUri)
            {
                return  _snspMemory.profilePicture.nextFileUri;
                
            }
            if(_snspMemory.profilePicture.hasFileUri)
            {
                return _snspMemory.profilePicture.fileUri;
            }
        }
    }*/
  
    /*if(_snspMemory.hasAvatarUrl)
        return _snspMemory.avatarUrl;*/
    
    if(_snspMemory.hasAvatarFileKey)
    {
        return [NSString stringWithFormat:@"%@", _snspMemory.avatarFileKey];
    }

    
    return @"headImage_boy.png";
}

-(NSString *)getGroupName
{
    NSString *gName = nil;
    if (_snspMemory.hasGroupName) {
        gName = [NSString stringWithString:_snspMemory.groupName];
    }
    return gName;
}

-(NSString*)fileName
{
    return nil;
}

-(NSString*)getName
{
    if(_snspMemory.hasName)
    {
        return _snspMemory.name;
    }
    return Unknown;
}

-(NSString*)getNickName
{
    if(_snspMemory.hasNickName)
    {
        return _snspMemory.nickName;
    }

    return Unknown;
}

-(NSString*)getOrganizationName
{
    if(_snspMemory.hasOrganizationName)
    {
        return _snspMemory.organizationName;
    }

    return Unknown;
}

-(SNSPSex)getSex
{
    if(_snspMemory.hasSex)
    {
        return _snspMemory.sex;
    }

    return SNSPSexKUnknown;
}

-(NSString*)getProfileTitle
{
    if(_snspMemory.hasProfileTitle)
    {
        return _snspMemory.profileTitle;
    }

    return Unknown;
}

-(int32_t)getClazzId
{
    if(_snspMemory.hasClazzId)
    {
        return _snspMemory.clazzId;
    }

    return 0;
}

-(NSString*)getSignature
{
    if(_snspMemory.hasSignature)
    {
        return _snspMemory.signature;
    }

    return @"";
}

-(int32_t)getMemoryId
{
    if(_snspMemory.hasMemoryId)
    {
        return _snspMemory.memoryId;
    }

    return 0;
}

-(SNSPMemoryPolicy)getPolicy
{
    if(_snspMemory.hasPolicy)
    {
        return _snspMemory.policy;
    }

    return 0;
}

-(BOOL)getIsFollowed
{
  
//    return [CHMemoryManager isFollowed:self];
    return YES;
    
}

-(BOOL)getIsChild
{

    if(_snspMemory.hasIsChild)
    {
        return _snspMemory.isChild;
    }

    return YES;
}

-(NSString*)getCheckCode
{
    if(_snspMemory.hasCheckCode)
    {
        return _snspMemory.checkCode;
    }
    return Unknown;
}

- (NSString *)getGardenName{
    if (_snspMemory.hasGardenName) {
        return _snspMemory.gardenName;
    }
    return Unknown;
}

- (NSString *)getGardenUrl{
    if (_snspMemory.hasGardenUrl) {
        return _snspMemory.gardenUrl;
    }
    return Unknown;
}

-(NSArray*)getPairsList
{
    return [_snspMemory pairsList];
}

-(NSArray*)getPostsList
{
    return nil;//[_snspMemory postsList];
}

-(NSArray*)getPhotosList
{
    return nil;
    //return [_snspMemory photosList];
}

-(SNSPPermission)getPermission
{
    if(_snspMemory.permissionList.count)return [[_snspMemory.permissionList objectAtIndex:0]integerValue];
    return 0;
}

-(ACTIVE_STATUS)getActiveStatus
{
    ACTIVE_STATUS status = ACTIVE_STATUS_NORMAL;
    if(!_snspMemory.activated)
    {
        status = ACTIVE_STATUS_UNACTIVE;
    }
    else
    {
        if(!_snspMemory.loggedOnRecently)
        {
            status = ACTIVE_STATUS_UNLOGINRECENTLY;
        }
        else
        {
            status = ACTIVE_STATUS_LOGINRECENTLY;
        }
    }
    
    return status;
//    return ACTIVE_STATUS_UNLOGINRECENTLY;
}


@end
